if(!dojo._hasResource["market.widgets.component.Pictures"]){
dojo._hasResource["market.widgets.component.Pictures"]=true;
require(["dojo/_base/declare","dojo/dom","market/widgets/CommonWidget","dojo/_base/array"],function(declare,dom,CommonWidget,array){
declare("market.widgets.component.Pictures",[CommonWidget],{
_templateHtml:'<div style="padding:5px;"><div class="sub_menu_title_right"><a href="#" id="hrefAddAlbum">{label1}</a></div><div class="clear"></div></div><div id="div_pictures_form_upload"></div>',
_UPLOAD_FORM:"market.widgets.component.Pictures.Upload",
albumUUID:null,_currentGenericForm:null,targetNode:null,
viewUploadFiles:function(){
   var args = {ajaxUrl:'participant/'+participant.id+'/file/upload',contentId:this.targetNode,callback:function(data){
      SYSTEMWIDGET.pictures().initViewUploadFiles(data);
   }};
   SYSTEMWIDGET.ajaxWidget(args).callXhrGetJson();
},
initViewUploadFiles:function(data){
   dijit.registry.remove("album.albumGUID_menu");
   var viewupload = dojo.replace(this._templateHtml, data);
   dojo.html.set(dom.byId(this.contentId), viewupload, {parseContent: false});
   var handleEvents = {click:this._handleClickEvents()};
   var postCreated=function(data){
      SYSTEMWIDGET.pictures().addToAlbums();
   };
   this._currentGenericForm = this.createFormFromDataSource(this._UPLOAD_FORM,"div_pictures_form_upload",data.formDataSource,handleEvents,postCreated);
},
uploadFiles:function(){
   var handleSuccess=function(data){
      SYSTEMWIDGET.messageWidget().showSucc(data.messageSucc);
      SYSTEMWIDGET.album().showAlbums();
   };
   this._currentGenericForm.callSaveForm({handleSuccess:handleSuccess});
},
addToAlbums:function(){
   var albums = SYSTEMWIDGET.album().getAlbums();
   var albumSelect = dijit.byId("album.albumGUID");
   albumSelect.options = [];
   albumSelect.addOption({value:"",label:""});
   array.forEach(albums, function(album, index){
      albumSelect.addOption({value:album.uuid, label:album.name});
   });
   dojo.query('#hrefAddAlbum').onclick(function(){
      SYSTEMWIDGET.album().showAddForm();
   });
},
_handleClickEvents: function(){
   var clickEvents = {events:['btnCancel','btnUpload'],
      btnCancel:function(data){
         SYSTEMWIDGET.album().showAlbums();},
      btnUpload:function(data){
         SYSTEMWIDGET.pictures().uploadFiles();
      }
   };
   return clickEvents;
}
});});}


